﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Dao;
using System.Data.SqlClient;
namespace 班级系统
{
    public partial class ClassSelect : Form
    {
        public ClassSelect()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            textBox1.Enabled = false;
            textBox2.Enabled = false;
            comboBox2.Enabled = false;
            string sql = "select school_name from school ";
            DataTable dt = sqlcontent.dt(sql);
            foreach (DataRow myRow in dt.Rows)
            {
                var sname = myRow[0].ToString();
                comboBox1.Items.Add(sname);
            }
            skinEngine1.SkinFile = "Wave.ssk";
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.Text != null)
            {
                comboBox2.Enabled = true;
                string schoolName = comboBox1.Text;
                string sql = "select d.department_name from department d,school s "
                + "where s.school_id=d.school_id and school_name=@schoolName";

                SqlParameter[] para = new SqlParameter[]{
                    new SqlParameter("schoolName",schoolName),
                };

                DataTable dt = sqlcontent.dt(sql, para);
                comboBox2.Items.Clear();
                comboBox3.Items.Clear();
                textBox1.Text = "";
                textBox2.Text = "";
                foreach (DataRow myRow in dt.Rows)
                {
                    var dname = myRow[0].ToString();
                    comboBox2.Items.Add(dname);
                }
            }

        }
        /// <summary>
        /// 逐步传递参数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox3.Text == "")
            {
                MessageBox.Show("请输入完整信息", "提示");
                return;
            }
            Student thou = new Student();
            string[] fom = new string[6];
            fom[0] = comboBox1.Text;
            fom[1] = comboBox2.Text;
            fom[2] = comboBox3.Text;
            fom[3] = dateTimePicker1.Text;
            fom[4] = textBox1.Text;
            fom[5] = textBox2.Text;
            thou.Form1S = fom;
            Student_In frm = new Student_In(this, thou);
            frm.Show();
            this.Hide();
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {

            if (comboBox2.Text == "")
            {
                return;
            }
            //添加系名称
            comboBox3.Items.Clear();
            string dname = comboBox2.Text;
            int departmentId = comboBox2.SelectedIndex + 1;
            string sql = "select class_name from class where department_id=@departmentId";
            SqlParameter[] para = new SqlParameter[]{
                new SqlParameter("departmentId",departmentId)
            };
            DataTable dt = sqlcontent.dt(sql, para);
            foreach (DataRow myrow in dt.Rows)
            {
                comboBox3.Items.Add(myrow[0].ToString());
            }
            comboBox3.Text = comboBox3.Items[0].ToString();

            //添加辅导员
            textBox1.Text = "";
            string className = comboBox3.Text;
            sql = "select department_teacher from department  where department_name=@dname";
            SqlParameter[] para1 = new SqlParameter[]{
              new SqlParameter("dname",dname),  
            };
            DataTable dt1 = sqlcontent.dt(sql, para1);
            foreach (DataRow myrow in dt1.Rows)
            {
                textBox1.Text = myrow[0].ToString();
            }
        }

        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {

        }

        private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            //添加班主任
            if (comboBox3.Text == "")
            {
                return;
            }

            textBox2.Text = "";
            string className = comboBox3.Text;
            string sql = "select class_teacher from class where class_name=@className";
            SqlParameter[] para = new SqlParameter[]{
              new SqlParameter("className",className),  
            };
            DataTable dt = sqlcontent.dt(sql, para);
            foreach (DataRow myrow in dt.Rows)
            {
                textBox2.Text = myrow[0].ToString();
            }

        }

        /// <summary>
        /// 皮肤选择
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void domainUpDown1_SelectedItemChanged(object sender, EventArgs e)
        {
            if (domainUpDown1.SelectedIndex == 0)
            {
                skinEngine1.SkinFile = "Silver.ssk";
                return;
            }
            if (domainUpDown1.SelectedIndex == 1)
            {
                skinEngine1.SkinFile = "WaveColor1.ssk";
                return;
            }
            if (domainUpDown1.SelectedIndex == 2)
            {
                skinEngine1.SkinFile = "WaveColor2.ssk";
                return;

            }


        }


    }
}
